<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/11/18
  Time: 10:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
            $("[name='uname']").blur(function(){
                //获得文本框中的内容
               var username= $(this).val();
               if($.trim(username).length==0){
                   alert("请输入用户名");
               }else{
                   //使用ajax发送数据给后台
                   $.ajax({
                       url:"/checkname",
                       data:"username="+username,
                       type:"post",
                       dataType:"json",
                       success:function(rs){
                         //  alert(rs.str);
                           $("[name='uname']").next().html(rs.str);

                       }
                   });
               }
            });
        })
    </script>
</head>
<body>
   <h1>ajax+json测试1:验证用户名是否可用</h1>
  <p>用户名:<input type="text" name="uname"><span></span> </p>
</body>
</html>
